package com.chapter14.Homework.homework01;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(new News("新冠确诊病例超千万，数百万印度教信徒赴横河“圣浴”引民众担忧"));
        list.add(new News("男子突然想起2个月前钓的鱼还在往兜里，捞起一看赶紧放生"));
        list.sort(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return -1;
            }
        });
        for (int i = 0; i < list.size(); i++) {
            News news = (News) list.get(i);
            System.out.println(show(news.getTitle()));
        }

    }

    public static String show(String list) {
        if (list.length() > 15){
            return list.substring(0,15) + "...";
        }
        return list;
    }
}

class News {
    private String title;
    private String content;

    public News(String title) {
        this.title = title;
    }

    public News(String title, String content) {
        this.title = title;
        this.content = content;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "新闻：" + title + "\t";
    }
}
